package com.telenav.ui;

import android.app.Activity;

public class AndroidActivity extends Activity {
	
	protected AndroidView currentScreen;
	
	public final void showScreen(AndroidView screen)
	{
        if (screen == null)
            return;

        if (screen.equals(currentScreen))
        {
        	screen.getView().postInvalidate();
        }
        else
        {
            currentScreen = screen;
            setContentView(screen.getView());    
        }
	}
	
    public AndroidView getCurrentScreen()
    {
        return this.currentScreen;
    }
    
    public void onBackPressed()
    {
    	if(currentScreen !=null && currentScreen.getCommandEventListener() != null)
    	{
            UiEvent uiEvent = new UiEvent(UiEvent.TYPE_KEY_EVENT);
            uiEvent.setKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
    		currentScreen.getCommandEventListener().handleUiEvent(uiEvent);
    	}
    	else
    	{
    		super.onBackPressed();
    	}
    	System.out.println("back");
    }

}
